<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1 id="time"></h1>
    <script>
	//倒计时函数：根据输入的时间，给出当前时间距离输入时间的倒计时内容；效果：距离某个时间，还有 x天x时x分x秒
    let inputTime = window.prompt('请输入时间：(格式为yyyy-mm-dd hh-mm-ss)');
 
    let timer = setInterval(()=>{
        let timeTamp = new Date().getTime();
        let inputtimeTape = new Date(inputTime).getTime();
        let leaveTime =(inputtimeTape - timeTamp) / 1000 ;
        let date = parseInt(leaveTime / (3600 * 24));
        let hour = parseInt(leaveTime / 3600 % 24);
        let minutes = parseInt(leaveTime / 60 % 60);
        let seconds = parseInt(leaveTime % 60);
        document.getElementById('time').innerHTML = `距离${inputTime}，还有${date}天${hour}时${minutes}分${seconds}秒`;
        if(timer == 0){
            clearInterval(timer);
        }
    },1000)




    </script>

</body>
</html>